import time

import cv2

from api.Common import isNPCGive
from api.DeviceOperator import initDeviceCommand

if __name__ == '__main__':
    # 初始化设备
    command = initDeviceCommand()

    # 根目录
    imgDir = "F:/Project/DeepLearning/Game/material/dataset/fourMan/original/material/"
    while True:
        # 显示图
        img = command.grab()
        # 将bgr转为rbg
        # rgb_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
        # 缩放到合适大小进行显示
        showImg = cv2.resize(img, (0, 0), fx=0.4, fy=0.4)
        cv2.imshow('mh', showImg)
        key = cv2.waitKey(5)
        if key == ord('q'):
            break
        elif key == ord('s'):
            command.save(f"{imgDir}{time.time()}.jpg")
        elif key == ord('c'):
            command.click(400, 270)
        elif key == ord('g'):
            print(isNPCGive(img))

    # output = adbutils.adb.device("127.0.0.1:16384").shell()
    # # 获取屏幕方向
    # # 获取屏幕分辨率
    # print(output)
    # |grep 'mCurrentOrientation='
    # |grep ''
    # output = adbutils.adb.device("127.0.0.1:16384").shell("dumpsys input")
    # print(output)
